package com.oldwine.mq.congif;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author oldwine
 * @date 2022/6/14
 */
@Configuration
public class FanoutConfig {

    /**
     * 声明一个Fanout类型的交换机
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("oldwine.fanout");
    }

    /**
     * 声明第一个队列
     * @return
     */
    @Bean
    public Queue queue1(){
        return new Queue("fanout.queue1");
    }

    /**
     * 绑定队列和交换机
     * @param fanoutExchange 交换机
     * @param queue1 队列
     * @return
     */
    @Bean
    public Binding bindingQueue1(FanoutExchange fanoutExchange,Queue queue1){
        return BindingBuilder.bind(queue1).to(fanoutExchange);
    }

    /**
     * 第二个队列
     * @return
     */
    @Bean
    public Queue queue2(){
        return new Queue("fanout.queue2");
    }

    /**
     * 将队列2绑定到交换机上
     * @param fanoutExchange
     * @param queue2
     * @return
     */
    public Binding bindingQueue2(FanoutExchange fanoutExchange,Queue queue2){
       return BindingBuilder.bind(queue2).to(fanoutExchange);
    }
}
